package com.example.chentian.weighttestcjy313;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    Button edButton,buttonImg,radioButton,checkButton;
    EditText editText;
    TextView showText;
    ImageView imageView;
    ImageButton newActivity;
    RadioButton radioBoy,radioGirl;
    CheckBox checkLanqiu,checkPing,checkZuqiu;

    boolean isChange = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        showText = (TextView) findViewById(R.id.tv_show);
        edButton = (Button) findViewById(R.id.ed_button);
        editText = (EditText) findViewById(R.id.ed_text);
        buttonImg = (Button) findViewById(R.id.button_img);
        imageView = (ImageView) findViewById(R.id.image_view);
        newActivity = (ImageButton) findViewById(R.id.new_activity);
        radioButton = (Button) findViewById(R.id.radio_button);
        radioBoy = (RadioButton) findViewById(R.id.radio_boy);
        radioGirl = (RadioButton) findViewById(R.id.radio_girl);
        checkButton = (Button) findViewById(R.id.check_button);
        checkLanqiu = (CheckBox) findViewById(R.id.check_lanqiu);
        checkPing = (CheckBox) findViewById(R.id.check_pingpang);
        checkZuqiu = (CheckBox) findViewById(R.id.check_zuqiu);

        edButton.setOnClickListener(this);
        buttonImg.setOnClickListener(this);
        newActivity.setOnClickListener(this);
        radioButton.setOnClickListener(this);
        checkButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ed_button:
                String str = editText.getText().toString();
                showText.setText(str);
                break;

            case R.id.button_img:
                if(!isChange){
                    imageView.setImageResource(R.mipmap.ic_launcher_round);
                    isChange = true;
                }
                else {
                    imageView.setImageResource(R.mipmap.ic_launcher);
                    isChange = false;
                }
                break;

            case R.id.new_activity:
                Intent intent = new Intent(MainActivity.this,NewActivity.class);
                intent.putExtra("name","欢迎来到空白的微信界面");
                startActivity(intent);
                break;

            case R.id.radio_button:
                if(radioBoy.isChecked()){
                    showText.setText("男");
                }else if(radioGirl.isChecked()){
                    showText.setText("女");
                }
                break;

            case R.id.check_button:
                String str2 = null;
                String str3 = null;
                String str4 = null;
                if(checkLanqiu.isChecked()){
                    str2 = "篮球";
                }else {
                    str2 = " ";
                }
                if(checkPing.isChecked()){
                    str3 = "乒乓";
                }else {
                    str3 = " ";
                }if(checkZuqiu.isChecked()){
                    str4 = "足球";
                }else {
                    str4 = " ";
                }
            showText.setText(str2+" "+str3+" "+str4);
        }
    }
}
